﻿using log4net;
using Quartz;
using System.Threading;
using System.Threading.Tasks;

namespace QuartzTest
{
    class LogSchedulerListener : ISchedulerListener
    {
        static readonly ILog log = LogManager.GetLogger(typeof(LogSchedulerListener));
        public Task JobAdded(IJobDetail jobDetail, CancellationToken cancellationToken = default)
        {
            log.Debug($"JobAdded key={jobDetail.Key}");
            return Task.CompletedTask;
        }

        public Task JobDeleted(JobKey jobKey, CancellationToken cancellationToken = default)
        {
            log.Debug($"JobDeleted jobKey={jobKey}");
            return Task.CompletedTask;
        }

        public Task JobInterrupted(JobKey jobKey, CancellationToken cancellationToken = default)
        {
            log.Debug($"JobInterrupted jobKey={jobKey}");
            return Task.CompletedTask;
        }

        public Task JobPaused(JobKey jobKey, CancellationToken cancellationToken = default)
        {
            log.Debug($"JobPaused jobKey={jobKey}");
            return Task.CompletedTask;
        }

        public Task JobResumed(JobKey jobKey, CancellationToken cancellationToken = default)
        {
            log.Debug($"JobResumed jobKey={jobKey}");
            return Task.CompletedTask;
        }

        public Task JobScheduled(ITrigger trigger, CancellationToken cancellationToken = default)
        {
            log.Debug($"JobResumed trigger={trigger.Key}");
            return Task.CompletedTask;
        }

        public Task JobsPaused(string jobGroup, CancellationToken cancellationToken = default)
        {
            log.Debug($"JobsPaused jobGroup={jobGroup}");
            return Task.CompletedTask;
        }

        public Task JobsResumed(string jobGroup, CancellationToken cancellationToken = default)
        {
            log.Debug($"JobsResumed jobGroup={jobGroup}");
            return Task.CompletedTask;
        }

        public Task JobUnscheduled(TriggerKey triggerKey, CancellationToken cancellationToken = default)
        {
            log.Debug($"JobUnscheduled triggerKey={triggerKey}");
            return Task.CompletedTask;
        }

        public Task SchedulerError(string msg, SchedulerException cause, CancellationToken cancellationToken = default)
        {
            log.Error($"SchedulerError {msg},cause={cause}");
            EE.LogError(msg, cause, log);
            return Task.CompletedTask;
        }

        public Task SchedulerInStandbyMode(CancellationToken cancellationToken = default)
        {
            log.Debug($"SchedulerInStandbyMode");
            return Task.CompletedTask;
        }

        public Task SchedulerShutdown(CancellationToken cancellationToken = default)
        {
            log.Debug($"SchedulerShutdown");
            return Task.CompletedTask;
        }

        public Task SchedulerShuttingdown(CancellationToken cancellationToken = default)
        {
            log.Debug($"SchedulerShuttingdown");
            return Task.CompletedTask;
        }

        public Task SchedulerStarted(CancellationToken cancellationToken = default)
        {
            log.Debug($"SchedulerStarted");
            return Task.CompletedTask;
        }

        public Task SchedulerStarting(CancellationToken cancellationToken = default)
        {
            log.Debug($"SchedulerStarting");
            return Task.CompletedTask;
        }

        public Task SchedulingDataCleared(CancellationToken cancellationToken = default)
        {
            log.Debug($"SchedulingDataCleared");
            return Task.CompletedTask;
        }

        public Task TriggerFinalized(ITrigger trigger, CancellationToken cancellationToken = default)
        {
            log.Debug($"TriggerFinalized,trigger={trigger.Key}");
            return Task.CompletedTask;
        }

        public Task TriggerPaused(TriggerKey triggerKey, CancellationToken cancellationToken = default)
        {
            log.Debug($"TriggerPaused,TriggerKey={triggerKey}");
            return Task.CompletedTask;
        }

        public Task TriggerResumed(TriggerKey triggerKey, CancellationToken cancellationToken = default)
        {
            log.Debug($"TriggerResumed,TriggerKey={triggerKey}");
            return Task.CompletedTask;
        }

        public Task TriggersPaused(string triggerGroup, CancellationToken cancellationToken = default)
        {
            log.Debug($"TriggersPaused,triggerGroup={triggerGroup}");
            return Task.CompletedTask; 
        }

        public Task TriggersResumed(string triggerGroup, CancellationToken cancellationToken = default)
        {
            log.Debug($"TriggersResumed,triggerGroup={triggerGroup}");
            return Task.CompletedTask;
        }
    }
}
